package com.hqully.labmanage.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.labmanage.domain.dto.LabManagerDTO;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.ResultVO;
import com.hqully.labmanage.service.LabManagerService;
import com.hqully.labmanage.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 实验室管理员数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-08 11:17:19
 */
@Api(tags = {"实验室管理员数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/lab-manager")
public class LabManagerController extends BaseController {

    @Resource
    private LabManagerService labManagerService;

    @ApiOperation(value = "分页条件查询实验室管理员列表")
    @GetMapping("/page-lab-managers")
    public ResultVO<PageInfo<LabManagerDTO>> pageLabManagers(PageDTO page, LabManagerDTO labManagerDTO) {
        PageInfo<LabManagerDTO> labManagerPage = labManagerService.pageLabManagers(page, labManagerDTO);
        return ResultVOUtil.success(labManagerPage);
    }

    @ApiOperation(value = "条件查询实验室管理员列表")
    @GetMapping("/list-lab-managers")
    public ResultVO<List<LabManagerDTO>> listLabManagers(LabManagerDTO labManagerDTO) {
        List<LabManagerDTO> labManagerList = labManagerService.listLabManagers(labManagerDTO);
        return ResultVOUtil.success(labManagerList);
    }

    @ApiOperation(value = "添加实验室管理员")
    @PostMapping("/add-lab-manager")
    public ResultVO<LabManagerDTO> addLabManager(@Validated @RequestBody LabManagerDTO labManagerDTO) {
        labManagerService.addLabManager(labManagerDTO);
        return ResultVOUtil.success("添加实验室管理员成功");
    }

    @ApiOperation(value = "更新实验室管理员")
    @PostMapping("/update-lab-manager")
    public ResultVO<LabManagerDTO> updateLabManager(@Validated @RequestBody LabManagerDTO labManagerDTO) {
        labManagerService.updateLabManager(labManagerDTO);
        return ResultVOUtil.success("更新实验室管理员成功");
    }

    @ApiOperation(value = "删除实验室管理员")
    @DeleteMapping("/delete-lab-manager/{id}")
    public ResultVO<LabManagerDTO> deleteLabManager(@PathVariable("id") String id) {
        labManagerService.deleteLabManagerById(id);
        return ResultVOUtil.success("删除实验室管理员成功");
    }

}

